package com.huaxin.hxmoduleworkorder.mapping;

import com.huaxin.hxenum.enums.Unit;
import com.huaxin.hxmoduleworkorder.common.enums.CustomerType;
import com.huaxin.hxmoduleworkorder.common.enums.InspectionOrderItemResultStatus;
import com.huaxin.hxmoduleworkorder.common.enums.InspectionTemplateItemType;
import com.huaxin.hxmoduleworkorder.dto.request.InspectionOrderItemCreateReqDTO;
import com.huaxin.hxmoduleworkorder.dto.request.InspectionOrderItemUpdateReqDTO;
import com.huaxin.hxmoduleworkorder.dto.response.InspectionReportOrderItemDTO;
import com.huaxin.hxmoduleworkorder.models.InspectionOrderItem;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

import java.util.List;

@Mapper(componentModel = "spring")
public interface InspectionOrderItemMapping {
    @Mapping(target = "type", ignore = true)
    @Mapping(target = "resultStatus", ignore = true)
    @Mapping(target = "customerType", ignore = true)
    @Mapping(target = "unit", ignore = true)
    InspectionOrderItem toEntity(InspectionOrderItemCreateReqDTO in);

    @AfterMapping
    default void afterMapping(InspectionOrderItemCreateReqDTO dto, @MappingTarget InspectionOrderItem entity) {
        entity.setType(InspectionTemplateItemType.of(dto.getType()));
        entity.setResultStatus(InspectionOrderItemResultStatus.of(dto.getResultStatus()));
        entity.setCustomerType(CustomerType.of(dto.getCustomerType()));
        entity.setUnit(Unit.of(dto.getUnit()));
    }

    @Mapping(target = "type", ignore = true)
    @Mapping(target = "resultStatus", ignore = true)
    @Mapping(target = "customerType", ignore = true)
    @Mapping(target = "unit", ignore = true)
    List<InspectionOrderItem> toEntityList(List<InspectionOrderItemCreateReqDTO> list);

    void updateEntity(InspectionOrderItemUpdateReqDTO in, @MappingTarget InspectionOrderItem entity);

    List<InspectionOrderItem> updateEntityList(List<InspectionOrderItemUpdateReqDTO> list);

    List<InspectionReportOrderItemDTO> toInspectionReportOrderItemDTOList(List<InspectionOrderItem> list);
}